import React from 'react'
import { BaseDetailPage, IBaseDetailPageState, IBaseDetailPageProps, http, routeUtils, uaaApp } from '@/lib'
import apis from '@/apis/TodoList'
import ButtonGroup from 'antd/lib/button/button-group'
import { Button } from 'antd'
import { settledReviewOpenModal, formatReviewProgreData } from '@/common/SettledReview'
import SettledReviewDetail from '@/components/SettledReviewDetail'
import ReviewHandleProgress from '@/components/ReviewHandleProgress'
import DetailReviewProgress from '../../component/DetailReviewProgress'
import { hasApproveSettledAuth } from '../../common'

export default class Index extends BaseDetailPage<ISettledReviewDetailProps, ISettledReviewDetailState> {

  private taskId
  private canReview
  private hasApproveAuth = hasApproveSettledAuth()
  constructor(props) {
    super(props)
    const { taskId, type, brandCode } = routeUtils.searchStringToObject(this.props.history.location.search, { taskId: '', type: '', brandCode: '' })
    this.taskId = taskId
    this.canReview = type == 1 // 待处理进入才可操作审批
    this.state = {
      title: '入驻审核',
      subTitle: '',
      queryAction: () => {
        return http.get(apis.settledReviewDetail, {
          params: {
            id: this.props.match.params.id,
            taskDefId: taskId,
            brandCode,
          }
        })
      }
    }
  }

  render() {
    const { dataSource } = this.state
    const processDetail = dataSource?.processDetailResult
    return super.render({
      body: (
        <>
          {/* <ReviewProgress /> */}
          <SettledReviewDetail dataSource={this.state.dataSource} />
          <DetailReviewProgress processDetail={processDetail} />
        </>
      ),
      footer: (
        <ButtonGroup>
          {(this.canReview && this.hasApproveAuth) && <Button type="primary" onClick={this.reviewHandle}>审批</Button>}
          {/* <Button type="danger" onClick={()=>this.reviewHandle(false)}>驳回</Button> */}
          {/* <Button onClick={() => this.props.history.goBack()}>返回</Button> */}
        </ButtonGroup>
      )
    })
  }

  public reviewHandle = () => {
    const { dataSource } = this.state
    const taskId = this.taskId
    const successSubmit = () => {
      this.props.history.goBack()
    }
    settledReviewOpenModal({ data: { ...dataSource, taskId }, successSubmit })
  }

}

interface ISettledReviewDetailProps extends IBaseDetailPageProps<{
  id: string
  taskId: string
}> {

}

interface ISettledReviewDetailState extends IBaseDetailPageState {

}
